# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=Net-SSLeay
pkgname=perl-${_realname}
pkgver=1.85
pkgrel=3
pkgdesc="Perl extension for using OpenSSL"
arch=('i686' 'x86_64')
license=('custom:BSD')
url="https://metacpan.org/${_realname}/"
groups=('perl-modules')
makedepends=('openssl-devel')
depends=('openssl')
options=(!emptydirs)
replaces=('net-ssleay')
provides=('net-ssleay')
source=("https://www.cpan.org/authors/id/M/MI/MIKEM/${_realname}-${pkgver}.tar.gz"
        'Net-SSLeay-1.55.patch')
sha256sums=('9d8188b9fb1cae3bd791979c20554925d5e94a138d00414f1a6814549927b0c8'
            '6f548646c89bb1af9ef286c07ae766dc28a03cbe17133caffcb295c3d4964df1')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  patch -p1 -i ${srcdir}/Net-SSLeay-1.55.patch

  sed -i \
      -e "/\$opts->{optimize} = '-O2 -g';/d" \
      inc/Module/Install/PRIVATE/Net/SSLeay.pm
}

build() {
  cd ${srcdir}/${_realname}-${pkgver}

  export OPTIMIZE="$CFLAGS"
  export OPENSSL_PREFIX=/usr

  # install module in vendor directories.
  PERL_MM_USE_DEFAULT=1 perl Makefile.PL -- INSTALLDIRS=vendor
  make
}

package() {
  cd ${srcdir}/${_realname}-${pkgver}

  make install DESTDIR=${pkgdir}
  install -D -m644 README "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
